home *** CD-ROM | disk | FTP | other *** search
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
- From: grantp@usa.pipeline.com(Pete Grant)
- Newsgroups: comp.lang.c++
- Subject: Re: Question about abstract base class
- Date: 18 Apr 1996 21:51:24 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4l6dgs$bno@news1.h1.usa.pipeline.com>
- References: <4l3u1s$j80@hermes.acs.unt.edu>
- NNTP-Posting-Host: 38.8.61.11
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete Grant)
- X-Newsreader: Pipeline v3.5.0
-
- On Apr 17, 1996 23:15:08 in article <Question about abstract base class>,
- 'cc0003@jove.acs.unt.edu (Chen-five Chi)' wrote:
-
-
- >I just wrote a simple program like this:
- >
- >class shape
- >
- >{
- >public:
- > virtual void print() const = 0;
- >........
- >}
- >clase TwoDimensionObject: public shape
- >{
- >public:
- > virtual void area() const = 0;
- >...
- >}
- >class Square: public TwoDimensionObject
- >{
- >private:
- > int side;
- >public:
- > virtual void area()
- ^^^^^
- You need const here also.
- > {
- > cout << "Square area: " << (side * side);
- > }
- >}
- >...
- >void main()
- >{
- > Square s1;
- >....
- >}
- >
- >==============================
- >And I get a compiler error in BC 4.51 said "s1 is abstract base class...."
-
- >After I move the keyword "const", the program runs normally without any
- >problem.
- >
- area() and area () const are two different functions. Your base class
- has two pure virtual functions which are not overridden in derived class:
- area(), as already pointed out, and print(), which is inherited from
- shape. You must define matching nonpure functions in Square before
- you can instantiate an object of that kind.
-
- >I would like to know
- >"Why I Could not put 'const' in the ABC? and the different these two?
- >
- The const specifier declares to the compiler that the function
- does not modify any of the instance variables (members), nor does
- it call any non-const member functions involving the object.
- --
- Pete Grant
- Kalevi, Inc.
- Software Engineering & development
-